﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class Hospital_HospitalHighPricedDrugsSetUp : BasePage
{
    public Hospital_HospitalHighPricedDrugsSetUp()
    { }
    int totalrecord = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        this.AspNetPager1.CurrentPageIndex = 1;
        BindData();
    }
    private void BindData()
    {
        HZ.Supervise.Model.Query.ProcureCatalog QProcureCatalog = new HZ.Supervise.Model.Query.ProcureCatalog();
        QProcureCatalog.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtProductName.Text.Trim());
        QProcureCatalog.MedicineModelName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtMedicineModelName.Text.Trim());
        QProcureCatalog.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtOutlookc.Text.Trim());
        QProcureCatalog.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_SC.Text.Trim());
        QProcureCatalog.CompanyName_TB = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_TB.Text.Trim());
        QProcureCatalog.SortFields = "ProductName asc,MedicineModelName asc,Outlookc asc";
        bool? bolisPrecious = null;
        if (this.DropDownList1.SelectedValue == "0")
        {
            bolisPrecious = false;
        }
        if (this.DropDownList1.SelectedValue == "1")
        {
            bolisPrecious = true;
        }
        if (this.DropDownList1.SelectedValue == "2")
        {
            bolisPrecious = null;
        }
        HZ.Supervise.IBLL.IBLL_ProcureCatalog iProcureCatalog = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
        DataTable dt = iProcureCatalog.GetIsPreciousProcureCatalog(QProcureCatalog, bolisPrecious, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
        AspNetPager1.RecordCount = totalrecord;
        this.gvwInfo.DataSource = dt;
        this.gvwInfo.DataBind();

    }
    protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
    {
        BindData();
    }
    protected void btnSet_Click(object sender, EventArgs e)
    {
        List<HZ.Supervise.Model.Insurance> insurancelist = new List<HZ.Supervise.Model.Insurance>();
        foreach (GridViewRow gvr in this.gvwInfo.Rows)
        {
            string strInsuranceType = gvr.Cells[9].Text;
            string strProcureCatalogID = gvr.Cells[1].Text;
            bool bolIsPrecious = true;
            CheckBox cb = (CheckBox)gvr.Cells[12].FindControl("CheckBox1");
            bolIsPrecious = cb.Checked;
            HZ.Supervise.Model.Insurance Minsurance = new HZ.Supervise.Model.Insurance();
            Minsurance.ProcureCatalogID = strProcureCatalogID;
            Minsurance.IsPrecious = bolIsPrecious;
            Minsurance.InsuranceType = strInsuranceType;
            insurancelist.Add(Minsurance);
        }
        HZ.Supervise.IBLL.IBLL_ProcureCatalog iProcureCatalog = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();
        try
        {
            int iresourt = iProcureCatalog.SetAsPreciousDrugs(insurancelist);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        BindData();
    }
    /// <summary>
    /// 转换布尔值为checked
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    protected string GetChecked(object obj)
    {
        if (obj.ToString() == true.ToString())
        {
            return "checked";
        }
        return "";
    }
    protected void btnExcel_Click(object sender, EventArgs e)
    {

        HZ.Supervise.Model.Query.ProcureCatalog QProcureCatalog = new HZ.Supervise.Model.Query.ProcureCatalog();
        QProcureCatalog.ProductName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtProductName.Text.Trim());
        QProcureCatalog.MedicineModelName = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtMedicineModelName.Text.Trim());
        QProcureCatalog.Outlookc = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtOutlookc.Text.Trim());
        QProcureCatalog.CompanyName_SC = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_SC.Text.Trim());
        QProcureCatalog.CompanyName_TB = HZ.Supervise.DAL.DAL_Helper.Replace(this.txtCompanyName_TB.Text.Trim());
        QProcureCatalog.SortFields = "ProductName asc,MedicineModelName asc,Outlookc asc";
        bool? bolisPrecious = null;
        if (this.DropDownList1.SelectedValue == "0")
        {
            bolisPrecious = false;
        }
        if (this.DropDownList1.SelectedValue == "1")
        {
            bolisPrecious = true;
        }
        if (this.DropDownList1.SelectedValue == "2")
        {
            bolisPrecious = null;
        }

        HZ.Supervise.IBLL.IBLL_ProcureCatalog iProcureCatalog = HZ.Supervise.BLLFactory.IBLL_ProcureCatalog();

        DataTable dt = iProcureCatalog.GetIsPreciousProcureCatalog(QProcureCatalog, bolisPrecious, 0, 0, out totalrecord);

        ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
    }
}
